package com.xzy.source;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.event.EventListener;

/**
 * 说明：
 *
 * @author xzy
 * @date 2023/3/19  20:05
 */
@Slf4j
public class PayloadEventListener {

    @EventListener
    public void stringPayloadEventListener(PayloadApplicationEvent<String> event) {
        log.info("received string payload event：{}", event.getPayload());
    }

    @EventListener
    public void integerPayloadEventListener(PayloadApplicationEvent<Integer> event) {
        log.info("received integer payload event：{}", event.getPayload());
    }

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(PayloadEventListener.class);
        applicationContext.refresh();

        applicationContext.publishEvent("hello world!");
        applicationContext.publishEvent(1024);
    }
}
